package com.card.db.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.card.db.dao.UserDao;
import com.card.db.entity.User;

@Database(version = 1,entities = {User.class},exportSchema = false)
public abstract class UserDatabase extends RoomDatabase {
    //利用单例模式提供数据库对象
    private static UserDatabase INSTANCE;



    /**
     * 对外暴露dao，用户可以直接拿这个使用
     * @return
     */
    public abstract UserDao getStudentDao();

    public static synchronized UserDatabase getInstance(Context context){
        if (INSTANCE == null){
            INSTANCE = Room.databaseBuilder
                    (context.getApplicationContext(), UserDatabase.class,"student_database").build();
        }
        return INSTANCE;
    }

}
